package cn.edu.njnu.opengmpback.resource.controller;


import cn.edu.njnu.opengmpback.common.utils.JsonResult;
import cn.edu.njnu.opengmpback.resource.entity.FileChunk;
import cn.edu.njnu.opengmpback.resource.service.FileTransferService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @Author wyjq
 * @Date 2022/03/24
 */

//@Api(tags = "大文件数据上传接口")
@CrossOrigin
@RestController
@RequestMapping(value = "/fileTransfer")
@Slf4j
public class FileTransferController {

    @Autowired
    FileTransferService fileTransferService;

    @ApiOperation(value = "上传大文件" )
    @PostMapping("/upload")
    public JsonResult uploadBigFile(
            @ModelAttribute FileChunk fileChunk,
            HttpServletResponse response){
        return fileTransferService.uploadBigFile(fileChunk,response);
    }

    @ApiOperation(value = "上传乱七八糟其他未分类文件，返回文件名" )
    @PostMapping("/uploadNoClassFile")
    public JsonResult uploadNoClassFile(
            @RequestPart("file") MultipartFile upFile,
            HttpServletResponse response){
        return fileTransferService.uploadNoClassFile(upFile,response);
    }

    @ApiOperation(value = "获取乱七八糟其他未分类文件" )
    @GetMapping("/getNoClassFile/{noClassFileName}")
    public void getNoClassFile(@PathVariable("noClassFileName") String noClassFileName,HttpServletResponse response){
        fileTransferService.getNoClassFile(noClassFileName,response);
    }

}
